//
//  CYGeRenZhuYe_XiangMuHaoTableViewCell2.m
//  cyydt
//
//  Created by chu on 2019/1/29.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYGeRenZhuYe_XiangMuHaoTableViewCell2.h"
#import "CYChanPinXiangQingViewController.h"

@implementation CYGeRenZhuYe_XiangMuHaoTableViewCell2

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
}

- (void)setModel:(CYProjectModel *)model{
    _model = model;
    [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:0];
    if (model.dpa_img_1) {
        [images addObject:model.dpa_img_1];
    }
    if (model.dpa_img_2) {
        [images addObject:model.dpa_img_2];
    }
    if (model.dpa_img_3) {
        [images addObject:model.dpa_img_3];
    }
    if (model.dpa_img_dan1) {
        [images addObject:model.dpa_img_dan1];
    }
    if (model.dpa_img_dan2) {
        [images addObject:model.dpa_img_dan2];
    }

    NSMutableArray *imageViews = [NSMutableArray arrayWithCapacity:0];

    if (images.count > 0) {
        for (int i = 0; i < images.count; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + i * 150 + i * 15, 8, 150, 90)];
            [imageView sd_setImageWithURL:[NSURL URLWithString:images[i]] placeholderImage:[UIImage imageWithColor:[UIColor lightGrayColor] Size:imageView.frame.size]];
            [self.scrollView addSubview:imageView];
            [imageViews addObject:imageView];
            
            [imageView setUserInteractionEnabled:YES];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAct:)];
            [imageView addGestureRecognizer:tap];
        }
        UIImageView *imageView = [imageViews lastObject];
        self.scrollView.contentSize = CGSizeMake(CGRectGetMaxX(imageView.frame) + 15, 90);
    }
}

- (void)tapAct:(UITapGestureRecognizer *)tap{
    CYChanPinXiangQingViewController *into = [[CYChanPinXiangQingViewController alloc] init];
    into.model = self.model;
    [[AppDelegate sharedAppDelegate] pushViewController:into];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
